package everydayGrade.t5;

import org.junit.jupiter.api.Test;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author: Siantar
 * @Date: 2023-07-19-10:27
 * @Description: 1.0
 */
public class T0874 {
    int[][] dict = new int[][]{{0, 1}, {-1, 0}, {0, -1}, {1, 0}};

    public int robotSim(int[] commands, int[][] obstacles) {
        Set<Integer> set = new HashSet<>();
        for (int[] p : obstacles) {
            set.add(p[0] * 30001 + p[1]);
        }
        int d = 0, x = 0, y = 0;
        int res = 0;
        for (int c : commands) {
            if (c == -2) {
                d = (d + 1) % 4;
            } else if (c == -1) {
                d = (d + 3) % 4;
            } else {
                while (c > 0) {
                    int cx = x + dict[d][0], cy = y + dict[d][1];
                    if (set.contains(cx * 30001 + cy)) break;
                    x = cx;
                    y = cy;
                    c--;
                }
                res = Math.max(res, x * x + y * y);
            }
        }
        return res;
    }

    @Test
    public void test() {
        System.out.println(Integer.MAX_VALUE);
    }
}
